home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PROG_TOO
/
C013.ZIP
/
HEAD.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
2KB
|
70 lines
/********************************************************************
* C Users Group (U.K) C Source Code Library File CUGLIB.013 *
* Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd. *
* Edgbaston, Birmingham B15 2QN ENGLAND *
********************************************************************
* File name: head.c
* Program name:head
* Source of file: Ron Wellstead
* Purpose: An MS-DOS copy of the UNIX utility of the same name.
* Changes: <who what when & why major changes have been made>
********************************************************************/
/*
*
* @(#) head.c 1.2 87/07/27
*
* UNIX style head utility for dos
*
* copyright (c) 1987 Ron Wellsted.
* This software is provided on the understanding that it is
* NOT to be used for commercial gain. It may be freely distributed
* in source or object form among amateur and hobby computer users ONLY!
*
* copies the first n lines of files (or stdin) to stdout.
* n defaults to 10
* usage: head [-nnn] [files...]
* written for Microsoft C, link with setargv.obj to expand wildcards
*/
#include <stdio.h>
char what[]="@(#) head VR 1.0.0 15 Jul 1987";
int count;
main(argc,argv)
int argc;
char *argv[];
{
FILE *fp;
if ((argc>1)&&(*argv[1]=='-')) {
--argc;
count=abs(atoi(*++argv));
} else count=10;
if (argc==1) /* no args; copy standard input */
filecopy(stdin);
else
while (--argc>0)
if ((fp=fopen(*++argv,"r"))==NULL) {
fprintf(stderr,"head: can't open %s\n",*argv);
exit(1);
} else {
filecopy(fp);
fclose(fp);
}
exit(0);
}
filecopy(fp)
FILE *fp;
{
int c,lines=1;
while ((c=getc(fp))!=EOF) {
putchar(c);
if (c=='\n') ++lines;
if (lines==count) break;
}
}